from sanic import Sanic
from sanic.response import text
from sanic.response import json
from sanic.exceptions import ServerError
app = Sanic("xuguoxu")

@app.route('/killme')
def i_am_ready_to_die(request):
    print(request.path)
    raise ServerError("Something bad happened", status_code=500)
@app.route("/")
async def test(request):
    return text("Hello world!")
@app.route("/getjson")
async def test(request):
    a= {'name': "xuguoxu", 'age': 2, 'b': '3'};
    return json(a)
@app.route("/tag/<tag>",methods=["post"])
async def tag_handler(request, tag):
    return text("Tag - {}".format(tag))
@app.middleware('request')
async def print_on_request(request):
    print("I print when a request is received by the server")
@app.middleware('response')
async def prevent_xss(request, response):
    response.headers["x-xss-protection"] = "1; mode=block"
app.run(host="0.0.0.0", port=8000, debug=True)